package SolveQuestions;

import java.util.ArrayList;
import java.util.Scanner;

public class huaWei0412_2 {
    private int maxFood = 0;

    public void getFood(int start, ArrayList<Integer>[] map, int[] seen, int food, int[] foods){
        if(food > maxFood) maxFood = food;
        for(int i = 0; i < map[start].size(); i ++) {
            if(seen[map[start].get(i)] != 1) {
                seen[map[start].get(i)] = 1;
                getFood(map[start].get(i), map, seen, food + foods[map[start].get(i)], foods);
            }
        }
    }
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        ArrayList<Integer>[] map = new ArrayList[n];
        int[] foods = new int[n];
        int[] seen = new int[n];
        for(int i = 0; i < n; i ++) {
            map[i] = new ArrayList<>();
        }
        for(int i = 0; i < n; i ++) {
            int id = input.nextInt();
            int parenId = input.nextInt();
            foods[id] = input.nextInt();
            if(parenId != -1) map[parenId].add(id);
        }

        huaWei0412_2 a =new huaWei0412_2();
        for(int i = 0; i < n; i ++) {
            seen[i] = 1;
            a.getFood(i, map, seen, foods[i], foods);
            seen[i] = 0;
        }

        System.out.printf("%d", a.maxFood);
    }
}
